import { ENUM_CLIP, ENUM_STATUS, ENUM_UI } from "../GbzEnum";
import GbzInstance from "../GbzInstance";
import GbzAudioManager from "../manager/GbzAudioManager";
import GbzDataManager from "../manager/GbzDataManager";
import GbzSdkManager from "../manager/GbzSdkManager";
import GbzToastManager from "../manager/GbzToastManager";
import BaseLayer from "./GbzBaselayer";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GbzLoseFullLayer extends BaseLayer {

    panel: cc.Node = null
    btn_restart: cc.Node = null
    btn_relive: cc.Node = null

    onLoad() {
        this.panel = cc.find('style/panel', this.node)
        this.btn_restart = cc.find('buttons/btn_restart', this.panel)
        this.btn_restart.on('click', this.onRestart, this)
        this.btn_relive = cc.find('buttons/btn_relive', this.panel)
        this.btn_relive.on('click', this.onRelive, this)
    }

    onDestroy() {
        this.btn_restart.off('click', this.onRestart, this)
        this.btn_relive.off('click', this.onRelive, this)
    }

    onEnable() {
        this.zoom(this.panel)
        GbzSdkManager.ins.showInter()
        GbzSdkManager.ins.showBanner(true)
    }

    onDisable() {
        GbzSdkManager.ins.showBanner(false)
    }

    async onRestart() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        await GbzInstance.fadeMgr.in()
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_LOSE_FULL, false)
        GbzInstance.gameMgr.onGameStart()
    }

    onRelive() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        GbzSdkManager.ins.showVideo(() => {
            GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_LOSE_FULL, false)
            GbzDataManager.ins.status = ENUM_STATUS.RUN
            GbzInstance.uiMgr.setMainCountDown(true)
            GbzInstance.gameMgr.onGameRevive()
        }, (msg: string) => {
            GbzToastManager.ins.show(msg, { gravity: 'TOP', bg_color: cc.color(226, 69, 109, 255) })
        })
    }
}
